package com.hns.can.mainte.service;

import com.hns.can.base.entity.SysUserEntity;
import com.hns.can.common.constants.GlobalConst;
import com.hns.can.common.formula.FillCodeDscValue;
import com.hns.can.common.formula.FillParamsVo;
import com.hns.can.mainte.entity.TCommGpsSwtcInfoEntity;
import com.hns.can.mainte.vo.TCommGpsSwtcCountVo;
import com.hns.frame.service.CommonService;
import com.hns.tool.pub.PubUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * GPS信号Service
 * @author:zhangzq
 * @email:
 * @version Revision 2.0.0
 */
@Service
public class GpsSignalService extends CommonService {

    @Autowired
    private FillCodeDscValue codeDscValue;

    private void fillInfoValue(List list) throws Exception {
        Map<String,String> map = new HashMap<String,String>();
        map.put("licPltNo", GlobalConst.DEFAULT_CACHE_VALUE);
        FillParamsVo vo = new FillParamsVo("carId", map);
        codeDscValue.fillInfoValue(list,new String[]{GlobalConst.CACHE_KEY_BASE_CAR_INFO},vo);
    }

    /**
     * 统计GPS信号次数
     * @param beginTime
     * * @param endTime
     * * @param lineId
     * @return
     * @throws Exception
     * @author:zhangzq
     * @email:
     */
    @Transactional
    public List<TCommGpsSwtcCountVo> getGpsSwtcCount(String beginTime,String endTime,String lineId) throws Exception {
        HashMap<String,String> map=new HashMap<String,String>();
        map.put("beginTime",beginTime);
        if (!PubUtil.isEmpty(endTime) && endTime.length() < 16) {
            endTime = endTime + " 23:59:59";
        }
        map.put("endTime",endTime);
        map.put("lineId",lineId);
        SysUserEntity user = (SysUserEntity)this.getCurrentUser().getUser();
        map.put("corpId",user.getCorpId());
        List<TCommGpsSwtcCountVo> list = PubUtil.convertListMapToObject(sqlMapDao.selectList("GpsSwtc.getGpsSwtcCount", map), TCommGpsSwtcCountVo.class);
        fillInfoValue(list);
        return list;
    }

    @Transactional
    public List<TCommGpsSwtcInfoEntity> getGpsSwtcListByCarId(String beginTime, String endTime, String carId) throws Exception {
        HashMap<String,String> map=new HashMap<String,String>();
        map.put("beginTime",beginTime);
        if (!PubUtil.isEmpty(endTime) && endTime.length() < 16) {
            endTime = endTime + " 23:59:59";
        }
        map.put("endTime",endTime);
        map.put("carId",carId);
        SysUserEntity user = (SysUserEntity)this.getCurrentUser().getUser();
        map.put("corpId",user.getCorpId());
        List<TCommGpsSwtcInfoEntity> list = PubUtil.convertListMapToObject(sqlMapDao.selectList("GpsSwtc.getGpsSwtcListByCarId", map), TCommGpsSwtcInfoEntity.class);
        fillInfoValue(list);
        return list;
    }

}
